#include "AnimableObject.h"


namespace askal
{
	AnimableObject::AnimableObject()
	{
		_mMeshPtr = NULL;
		_mSkeletonPtr = NULL;
		_mTexture = "";
		
		askal::AnimationController a;
		_mAnimationController = a;
		
		_mVisible = true;
	}
	
	AnimableObject::AnimableObject(chstr mesh, chstr skeleton, chstr texture)
	{
		_mMeshPtr = askal::AskalDataCache::Instance()->getMesh(mesh);
		_mSkeletonPtr = askal::AskalDataCache::Instance()->getSkeleton(skeleton);
		_mTexture = texture;
		
		askal::AnimationController a;
		_mAnimationController = a;
		
		_mVisible = true;
	}
	
	AnimableObject::~AnimableObject()
	{
		
	}
	
	void AnimableObject::setVisible(bool visible)
	{
		_mVisible = visible;
	}
	
	AnimationController* AnimableObject::getAnimatonController()
	{
		return &_mAnimationController;
	}
	
	void AnimableObject::useMesh(chstr mesh)
	{
		_mMeshPtr = askal::AskalDataCache::Instance()->getMesh(mesh);
		_mAnimationController.assignMesh(mesh);
	}
	
	void AnimableObject::useSkeleton(chstr skeleton)
	{
		_mSkeletonPtr = askal::AskalDataCache::Instance()->getSkeleton(skeleton);
		_mAnimationController.assignSkeleton(skeleton);
	}
	
	void AnimableObject::useTexture(chstr texture)
	{
		_mTexture = texture;
	}
	
	const harray<April::PlainVertex>& AnimableObject::getMeshVertexBatch() const
	{
		return _mMeshVertexBatch;
	}
	
	const harray<April::PlainVertex>& AnimableObject::getSkeletonVertexBatch() const
	{
		return _mSkeletonVertexBatch;
	}
	void AnimableObject::update(float dt)
	{
		_mAnimationController.update(dt);
		
		if(_mVisible)
		{
			// if update skeleton
			_mAnimationController.updateSkeletonVertexBatch(&_mSkeletonVertexBatch);
			// if update mesh
			_mAnimationController.updateMeshVertexBatch(&_mMeshVertexBatch);
		}
	}
	
}